#!/bin/bash # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Desktop Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description - Script to add Wifi Profile # Parameters - "" "" # Remarks - To add a Wifi Profile in the computer # Configuration Type - COMPUTER AIRPORT_LINE=$(networksetup -listnetworkserviceorder | grep "Port: W"); AIRPORT=${AIRPORT_LINE:31:3} WIFI_NETWORK_NAME=$1 WIFI_PASSWORD=$2 #WIFI_SECURITY=$3 #For security type, use OPEN for none, WPA for WPA Personal, WPA2 for WPA2 Personal, WPA/WPA2 for WPA/WPA2 Personal, WPAE for WPA Enterprise, WPA2E for WPA2 Enterprise, WPAE/WPA2E for WPA/WPA2 Enterprise, WEP for plain WEP, and 8021XWEP for 802.1X WEP. networksetup -setairportpower $AIRPORT off networksetup -setairportpower $AIRPORT on sleep 2 if networksetup -getairportnetwork $AIRPORT | grep -i -a "$WIFI_NETWORK_NAME" ; then echo 'Connected!'; exit 0 else echo 'Allo 1' fi #if networksetup -addpreferredwirelessnetworkatindex $AIRPORT "$WIFI_NETWORK_NAME" 0 "$WIFI_SECURITY" "WIFI_PASSWORD" | grep -i -a "Failed" ; if networksetup -setairportnetwork $AIRPORT "$WIFI_NETWORK_NAME" "$WIFI_PASSWORD" | grep -i -a "Failed" ; then echo 'Failed to connect, just restarting...'; networksetup -setairportpower $AIRPORT off networksetup -setairportpower $AIRPORT on sleep 1 else echo 'Allo 2' fi networksetup -getairportnetwork $AIRPORT